import java.awt.event.*;
import javax.swing.*;
public class WindowExit extends JFrame {
   JMenuBar menubar;
   JMenu menu;
   JMenuItem  itemExit;
   public WindowExit() {
      init();
      setBounds(100,100,150,150);
      setVisible(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
   void init(){ 
      menubar=new JMenuBar(); 
      menu=new JMenu("文件");   
      itemExit=new JMenuItem("退出");
      itemExit.setAccelerator(KeyStroke.getKeyStroke(
                              KeyEvent.VK_E,InputEvent.CTRL_MASK));
      menu.add(itemExit);
      menubar.add(menu);
      setJMenuBar(menubar);
      itemExit.addActionListener(new ActionListener(){
                                   public void actionPerformed(ActionEvent e){
                                      System.exit(0);
                                   } 
                                 });
     
    }
}
    

